package com.app.controller.backstage;

import com.app.common.Result;
import com.app.model.AdminUserModel;
import com.app.service.AdminUserService;
import com.app.service.BrowseNumberService;
import com.app.service.ComplaintService;
import com.app.service.UserService;
import com.app.util.TokenUtils;
import com.app.vo.CensusVo;
import com.app.vo.MsgVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@Controller
@RequestMapping("/behind")
public class CensusBehindController {
    @Autowired
    private UserService userService;
    @Autowired
    private ComplaintService complaintService;


    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    private BrowseNumberService browseNumberService;

    /**
     * 统计数量
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/getBehindCensus")
    public Result<Object> getBehindCensus() {
        CensusVo vo = new CensusVo();
        //投诉总数
        int allCount = complaintService.selectAllCount();
        //已办结总数
        int statusCount = complaintService.selectStatusCount();
        //用户总数
        int userAllCount = userService.selectAllCount();
        //用户访问量
        int userCount = browseNumberService.selectCount();
        vo.setAllCount(allCount);
        vo.setStatusCount(statusCount);
        vo.setUserAllCount(userAllCount);
        vo.setUserCount(userCount);
        return Result.success(vo);
    }

    //饼图
    @GetMapping("/getBehindPie")
    public Result<Object> getBehindPie() {
        MsgVo vo = new MsgVo();
        vo.setName("建设");
        vo.setValue(complaintService.selectByType(1));
        MsgVo vo1 = new MsgVo();
        vo1.setName("非建设");
        vo1.setValue(complaintService.selectByType(2));
        MsgVo vo3 = new MsgVo();
        vo3.setName("待办理");
        vo3.setValue(complaintService.selectByStatus(1));
        MsgVo vo4 = new MsgVo();
        vo4.setName("已办结");
        vo4.setValue(complaintService.selectByStatus(2));
        MsgVo vo5 = new MsgVo();
        vo5.setName("驳回");
        vo5.setValue(complaintService.selectByStatus(3));
        MsgVo vo6 = new MsgVo();
        vo6.setName("处理中");
        vo6.setValue(complaintService.selectByStatus(4));
        List<MsgVo> voList = new ArrayList<>();
        voList.add(vo);
        voList.add(vo1);
        voList.add(vo3);
        voList.add(vo4);
        voList.add(vo5);
        voList.add(vo6);
        return Result.success(voList);
    }
}